import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../PublicSource/widgets/common_widget.dart';
import '../../app_files.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    UserLoginState state, Dispatch dispatch, ViewService viewService) {
  return WillPopScope(
      child: Scaffold(
        resizeToAvoidBottomPadding: true,
        backgroundColor: Colors.white,
        body: GestureDetector(
          child: Stack(
            children: [
              Positioned(
                child: Image.asset(
                  'images/login_bg.png',
                  fit: BoxFit.fitWidth,
                  width: double.infinity,
                ),
                top: 0,
                left: 0,
                right: 0,
              ),
              Positioned(
                child: Image.asset(
                  'images/lg_bottom.png',
                  width: double.infinity,
                  fit: BoxFit.fitWidth,
                ),
                bottom: 0,
                left: 0,
                right: 0,
              ),
              Container(
                width: double.infinity,
                height: double.infinity,
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(
                          top: 20 + ScreenUtil.statusBarHeight,
                        ),
                        child: Image.asset('images/login_logo.png',width: 75,fit: BoxFit.fitWidth,),
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 9, bottom: 8),
                        child: Text(
                          '气通千里 万家旺火',
                          style: TextStyle(
                            color: Color(0xfffafafa),
                            fontSize: 15,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(right: 14, ),
                        child:  MyInkWellWidget(
                          child: Row(
                            children: [
                              Expanded(child: Container()),
                              Container(
                                decoration: BoxDecoration(
                                  color: ThemeConfig.rgba(255, 255, 255, 0.1),
                                  borderRadius:
                                  BorderRadius.all(Radius.circular(5)),
                                ),
                                height: 30,
                                padding: EdgeInsets.only(left: 5, right: 5),
                                child: Row(
                                  children: [
                                    Image.asset('images/user_staff.png'),
                                    Padding(
                                      padding: EdgeInsets.only(left: 4),
                                      child: Text(
                                        '我是员工',
                                        style: TextThemeConfig.Font13WithColorWhite,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                          onTap: () => Navigator.pop(viewService.context),
                        ),
                      ),

                      Container(
                        padding: EdgeInsets.only(top: 20, left: 16, right: 16),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(20),
                              topRight: Radius.circular(20)),
                          color: Colors.white,
                          boxShadow: [
                            BoxShadow(
                              color: Color(0xff4D81EF),
                              blurRadius: 16,
                            ),
                          ],
                        ),
                        child: Column(
                          children: [
                            Image.asset('images/user_login.png'),
                            Container(
                              margin: EdgeInsets.only(top: 20, bottom: 20),
                              decoration: BoxDecoration(
                                borderRadius:
                                BorderRadius.all(Radius.circular(5)),
                                color: Color(0xffE8F2FC),
                              ),
                              child: Row(
                                children: [
                                  Container(
                                    width: 40,
                                    child: Align(
                                      child: Image.asset('images/lg_account.png'),
                                    ),
                                  ),
                                  Container(
                                    color: ThemeConfig.rgba(75, 124, 228, 0.25),
                                    height: 20,
                                    width: 1,
                                  ),
                                  Expanded(
                                    child: Container(
                                      padding:
                                      EdgeInsets.only(left: 14, right: 10),
                                      child: TextField(
                                        textInputAction: TextInputAction.done,
                                        controller: state.phoneController,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: ThemeConfig.mainColor),
//                      keyboardType: TextInputType.phone,
                                        decoration: InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "请输入您的手机号",
                                          hintStyle: TextStyle(
                                              fontSize: 14,
                                              color: ThemeConfig.mainColor),
                                        ),
                                        onChanged: (String str) {
                                          if (str.length >
                                              ThemeConfig.passwordTextLength)
                                            state.phoneController.text =
                                                str.substring(
                                                    0,
                                                    ThemeConfig
                                                        .passwordTextLength);
                                        },
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),
                            Container(
                              decoration: BoxDecoration(
                                borderRadius:
                                BorderRadius.all(Radius.circular(5)),
                                color: Color(0xffE8F2FC),
                              ),
                              child: Row(
                                children: [
                                  Container(
                                    width: 40,
                                    child: Align(
                                      child:
                                      Image.asset('images/lg_password.png'),
                                    ),
                                  ),
                                  Container(
                                    color: ThemeConfig.rgba(75, 124, 228, 0.25),
                                    height: 20,
                                    width: 1,
                                  ),
                                  Expanded(
                                    child: Container(
                                      padding:
                                      EdgeInsets.only(left: 14, right: 10),
                                      child: TextField(
                                        controller: state.passwordController,
                                        textInputAction: TextInputAction.done,
                                        obscureText: true,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: ThemeConfig.mainColor),
                                        decoration: InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "请输入您的密码",
                                          hintStyle: TextStyle(
                                            fontSize: 14,
                                            color: ThemeConfig.mainColor,
                                          ),
                                        ),
                                        onChanged: (String str) {
                                          if (str.length >
                                              ThemeConfig.passwordTextLength)
                                            state.passwordController.text =
                                                str.substring(
                                                    0,
                                                    ThemeConfig
                                                        .passwordTextLength);
                                        },
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),
                            Expanded(child: Container()),
                            Container(
                              margin: EdgeInsets.only(left: 17, right: 17),
                              height: 50,
                              decoration: BoxDecoration(
                                color: ThemeConfig.mainColor,
                                borderRadius:
                                BorderRadius.all(Radius.circular(4)),
                              ),
                              child: InkWell(
                                child: Center(
                                  child: Text(
                                    '立即登陆',
                                    style: TextThemeConfig.Font18WithColorWhite,
                                  ),
                                ),
                                onTap: () =>
                                    dispatch(UserLoginActionCreator.onSubmit()),
                              ),
                            ),
                            Padding(
                              padding: EdgeInsets.only(bottom: 20, top: 20),
                              // child: InkWell(
                              //     child: Text(
                              //       '游客身份',
                              //       style: TextThemeConfig.Font13WithColor99,
                              //     ),
                              //     onTap: () {
                              //       UserInfoEntity info =
                              //           GlobalStore.store.getState().userInfo;
                              //       info.isGsUser = false;
                              //       GlobalStore.store.dispatch(
                              //           GlobalActionCreator.onUserLogin(info));
                              //       bus.emit('setGasUser');
                              //       Navigator.popUntil(viewService.context, ModalRoute.withName('/'));
                              //     }),
                            ),
                          ],
                        ),
                        width: double.infinity,
                        margin: EdgeInsets.only(top: 12, left: 17, right: 17),
                        height: 390,
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 20),
                        child: InkWell(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                '还没有账号？',
                                style: TextThemeConfig.Font13WithColor99,
                              ),
                              Text(
                                '注册',
                                style: TextThemeConfig.Font13WithColorblue,
                              )
                            ],
                          ),
                          onTap: () =>
                              dispatch(UserLoginActionCreator.onTapRegister()),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
          behavior: HitTestBehavior.translucent,
          onTap: () => CommonUtils.closeKey(viewService.context),
        ),
      ),
      onWillPop: () async {
        return false;
      });
}
